package com.bdqn.wx.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public final class HibernateUtil {

	private static Configuration cfg = null;
	private static SessionFactory sessionFactory = null;

	private static ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();

	static {

		cfg = new Configuration().configure();
		sessionFactory = cfg.buildSessionFactory();

	}

	public static Session getSession() {
		Session session = threadLocal.get();
		if (session == null || !session.isOpen()) {
			session = sessionFactory.openSession();
			threadLocal.set(session);
		}
		return session;

	}

}
